#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
int month[] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
int get_day(int y, int m)
{
    if (m == 2 && (y % 4 == 0 && y % 100 != 0) || y % 400 == 0) return month[2] + 1;
    return month[m];
}
int is_legal(int y)
{
    string s = to_string(y);
    string s1(1, s[3]);
    s1 += s[2];
    string s2(1, s[1]);
    s2 += s[0];
    int m = stoi(s1);
    int d = stoi(s2);
    if (m > 12 || m < 1) return 0;
    if (d > get_day(y, m)) return 0;
    if (s[0] == s[2] && s[1] == s[3] && s[0] != s[1]) return 2;
    return 1;
}
int main()
{
    string str;
    cin >> str;
    int y = stoi(str.substr(0, 4));
    int a = 0;
    for (int i = y; i <= 9999; i++)
    {
        int res = is_legal(i);
        if (res > 0)
        {
            string s = to_string(i);
            string s1 = s;
            reverse(s1.begin(), s1.end());
            string s2 = s + s1;
            if (s2 > str)
            {
                a = i;
                cout << s2 << endl;
                if (res == 2)
                {
                    cout << s2 << endl;
                    return 0;
                }
                break;
            }
        }
    }
    for (int i = a + 1; i <= 9999; i++)
    {
        if (is_legal(i) == 2)
        {
            string s = to_string(i);
            cout << s;
            reverse(s.begin(), s.end());
            cout << s << endl;
            break;
        }
    }
    return 0;
}